package cwinsor.raking.year2014;

import java.util.Arrays;
import java.util.List;


public final class Day {
	private static String dS = "Day";

	private Day(String n) { name = n; } // private constructor

	private String name;

	public final String name() { return name; }

	public static final Day NOV_2 = new Day("11/2/13");
	public static final Day NOV_3 = new Day("11/3/13");
	public static final Day NOV_9 = new Day("11/9/13");
	public static final Day NOV_10 = new Day("11/10/13");

	public static final List<Day> DAYS = Arrays.asList(
			NOV_2,
			NOV_3,
			NOV_9,
			NOV_10);



	/*
	 * stringToDay
	 * converts string to Day
	 */
	public static final Day stringContainsDay(String theString) {
		return stringContainsDay(theString, true);
	}

	public static final Day stringContainsDay(String theString, boolean failIfNotFound) {

		// if the user sends a null string, but also has cleared failIfNotFound
		// then return a null back
		if ((theString == null) && (!failIfNotFound)) {
			return null;
		}

		// regular cases
		if (theString.contains(NOV_2.name())) { return NOV_2; }
		if (theString.contains(NOV_3.name())) { return NOV_3; }
		if (theString.contains(NOV_9.name())) { return NOV_9; }
		if (theString.contains(NOV_10.name())) { return NOV_10; }
		// default
		if (failIfNotFound) {
			Msg.fatal(dS + "in stringContainsDay - cannot convert "
					+ theString 
					+ " to a Day");
			System.exit(1);
		}
		return null;
	}
}
